{$R-}

(*
	speak string[,phonemes?] -- Speak the string, either as text or as phonemes. If the last parameter is present,
		use phonemes, otherwise translate the text in string into phonemes first.

	To compile and link this file using Macintosh Programmer's Workshop,

	pascal -w speak.p
	link -m ENTRYPOINT -o WildSpeak -rt XCMD=0 -sn Main=speak speak.p.o SpeechIntf.o "{MPW}"Libraries:interface.o
	
*)

{$S speak } 	{ Segment name must be the same as the command name. }

unit DummyUnit;

interface

uses MemTypes, QuickDraw, OSIntf, HyperXCmd, SpeechIntf;

procedure EntryPoint(paramPtr: XCmdPtr);
	
implementation

type

Str31 = String[31];

procedure speak(paramPtr: XCmdPtr); forward;

procedure EntryPoint(paramPtr: XCmdPtr);

	begin
		speak(paramPtr);
	end;

procedure speak(paramPtr: XCmdPtr);

	var portNumber: integer;
		setting: integer;
		inPort, outPort: integer;
		str: Str255;

	{$I XCmdGlue.inc}

	procedure Fail(errMsg: Str255); { set theResult and quit }
		begin
			paramPtr^.returnValue := PasToZero(errMsg);
			exit(speak);
		end;


var

SpeakHandle: SpeechHandle;
usePhonemes: boolean;
dummy: integer;
theSpeech: Handle;

begin
	if (paramPtr^.paramCount <> 1) and (paramPtr^.paramCount <> 2) then Fail('wrong number of parameters');
	usePhonemes := paramPtr^.paramCount = 2;

	if SpeechOn('',SpeakHandle) = noErr then
		begin
			if GetHandleSize(paramPtr^.params[1]) > 1 then
				begin
					if usePhonemes then
						begin
							theSpeech := paramPtr^.params[1];
							if HandToHand(theSpeech) = noErr then
								begin
									SetHandleSize(theSpeech,GetHandleSize(theSpeech)-1);
									dummy := MacinTalk(SpeakHandle,paramPtr^.params[1]);
									DisposHandle(theSpeech);
								end;
						end
					else
						begin
							theSpeech := NewHandle(0);
							HLock(paramPtr^.params[1]);
							if Reader(SpeakHandle,paramPtr^.params[1]^,GetHandleSize(paramPtr^.params[1])-1,theSpeech) = noErr then
								dummy := MacinTalk(SpeakHandle,theSpeech);
							HUnlock(paramPtr^.params[1]);
							DisposHandle(theSpeech);
						end;
				end;
			SpeechOff(SpeakHandle);
		end
	else Fail('SpeechOn failed');
end;

end.
